import 'package:city_corner/login-page/login-model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

class MyTextField extends StatefulWidget {
  final String placeholder;
  final String label;
  final Function setValue;
  MyTextField({this.placeholder, this.label, this.setValue});

  @override
  State<StatefulWidget> createState() => _MyTextFieldState();
}

class _MyTextFieldState extends State<MyTextField> {
  TextInputType setTextType() {
    return widget.label == 'passwd'
        ? TextInputType.emailAddress
        : TextInputType.visiblePassword;
  }

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider<LoginModel>(
        create: (context) => LoginModel(),
        child: CupertinoTextField(
            onTap: () {
              Provider.of<LoginModel>(context, listen: false).setTop(100);
            },
            onChanged: (value) {
              widget.setValue(widget.label, value);
            },
            placeholder: widget.placeholder,
            keyboardType: setTextType()));
  }
}
